import { BasicColumn, FormSchema } from "/@/components/Table"
import { render } from "/@/utils/common/renderUtils"
import { UploadBizType } from "/@/enums/uploadEnum"
import { PageEnum } from "/@/enums/pageEnum"
import { DescItem } from "/@/components/Description/index"
import { JVxeTypes, JVxeColumn } from "/@/components/jeecg/JVxeTable/types"

export const columns: BasicColumn[] = [
  {
    title: "图标",
    dataIndex: "logo",
    align: "left",
    width: 50,
    customRender: ({ text }) => {
      return render.renderImagePreview({
        imageList: [{ src: text, width: 45, preview: false }],
      })
    },
  },
  {
    title: "登录模式",
    width: 150,
    align: "left",
    dataIndex: "name",
  },
  {
    title: "场景",
    width: 150,
    dataIndex: "sceneNames",
    customRender: ({ text }) => {
      return render.renderTag(text, "green")
    },
  },
]

export const formSchema: FormSchema[] = [
  {
    field: "id",
    label: "id",
    component: "Input",
    show: false,
  },
  {
    field: "hasClient",
    label: "hasClient",
    component: "Input",
    show: false,
  },
  {
    field: "name",
    label: "名称",
    component: "Input",
    required: true,
  },
  {
    field: "type",
    label: "类型",
    dynamicDisabled: ({ values }) => !!values.id,
    component: "Input",
    required: true,
  },
  {
    label: "场景",
    field: "scenes",
    required: true,
    component: "JDictSelectTag",
    slot: "loginScenes",
  },
  {
    label: "表单字段",
    field: "diyFormId",
    required: false,
    component: "Input",
    slot: "diyForm",
  },

  {
    field: "displayName",
    label: "显示名称",
    component: "Input",
  },
  {
    label: "描述",
    field: "description",
    component: "InputTextArea",
    componentProps: {
      placeholder: "请输入描述",
      rows: 3,
    },
  },

  {
    label: "图标",
    field: "logo",
    component: "MyImageUpload",
    componentProps: {
      fileMax: 1,
      bizType: UploadBizType.IamSocial,
    },
  },
]

export const formDetailSchema: DescItem[] = [
  {
    field: "name",
    label: "名称",
  },
  {
    field: "type",
    label: "标识",
  },
  {
    field: "configKey",
    label: "去配置",
    render: (curVal, data) => {
      return render.renderHref({
        url: `${PageEnum.CONFIG_CENTER}?configKey=${curVal}`,
        text: `点我去配置 ${curVal}`
      })
    },
  },

  {
    field: "scenes",
    label: "场景",
    render: (curVal, data) => {
      return render.renderTag(render.renderDict(curVal, "login_scene"), "green")
    },
  },
  {
    field: "logo",
    label: "图标",
    render: (curVal, data) => {
      return render.renderImagePreview({
        imageList: [{ src: curVal, width: 80 }],
      })
    },
  }
]
